package com.xc.controller.backend;

import com.xc.common.ServerResponse;
import com.xc.pojo.AgentUser;
import com.xc.service.IAgentUserService;
import com.xc.service.IUserPositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;

/**
 * @author mipha
 * @version 1.0
 * @date 2019/2/26 3:44 PM
 */
@Controller
@RequestMapping("/admin/agent/")
@Slf4j
public class AdminAgentController {

    @Autowired
    IAgentUserService iAgentUserService;
    @Autowired
    IUserPositionService iUserPositionService;

    /**
     *  查询代理列表
     * @param realName
     * @param phone
     * @param pageNum
     * @param pageSize
     * @param request
     * @return
     */
    @RequestMapping("list.do")
    @ResponseBody
    public ServerResponse list(@RequestParam(value = "realName",required = false) String realName
            , @RequestParam(value = "phone",required = false) String phone
            , @RequestParam(value = "pageNum", defaultValue = "1") int pageNum
            , @RequestParam(value = "pageSize", defaultValue = "12") int pageSize
            , HttpServletRequest request){
        return iAgentUserService.listByAdmin(realName ,phone ,pageNum ,pageSize ,request);
    }

    /**
     *  添加 代理用户
     * @param agentUser
     * @return
     */
    @RequestMapping("add.do")
    @ResponseBody
    public ServerResponse add(AgentUser agentUser){
        return iAgentUserService.add(agentUser);
    }

    /**
     *  修改 代理用户
     * @param agentUser
     * @return
     */
    @RequestMapping("update.do")
    @ResponseBody
    public ServerResponse update(AgentUser agentUser){
        return iAgentUserService.update(agentUser);
    }

    /**
     *  查询代理的总反佣
     * @param agentId 代理ID
     * @param positionType 正式持仓0 / 模拟持仓1
     * @param beginTime 开始时间
     * @param endTime 结束时间
     * @param request
     * @return
     */
    @RequestMapping("getIncome.do")
    @ResponseBody
    public ServerResponse getIncome(
            @RequestParam(value = "agentId",required = false) Integer agentId
            ,@RequestParam(value = "positionType", required = false) Integer positionType
            , @RequestParam(value = "beginTime",required = false) String beginTime
            , @RequestParam(value = "endTime",required = false) String endTime
            , HttpServletRequest request){
        return iUserPositionService.getIncome(agentId,positionType,beginTime,endTime);
    }




}
